package think.in.java.concurrency.PractiseOneMoreTime;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Repeat Exercise 1 using the different types of executors shown in this section..
 */
public class Exec3ForExecutor implements Runnable {
    public  Exec3ForExecutor(){
        System.out.println(Thread.currentThread().getName()+"Start!");
    }
    @Override
    public void run() {
        for(int i =0 ; i <3 ;i++){
            System.out.println(Thread.currentThread().getName()+"In side the thread");
            Thread.yield();
        }
        System.out.println(Thread.currentThread().getName()+"Ending");
    }

    public static void main(String[] args){
        ExecutorService executor = Executors.newFixedThreadPool(3);

        for(int i =0; i<3;i++)
            executor.execute(new Exec3ForExecutor());
        executor.shutdown();// the executor must be shut down
    }
}
